import { RouteRecordRaw } from "vue-router";
import Index from "@/Index.vue";
import LoginAndRegister from "@views/LoginAndRegister.vue";
import Home from "@views/Home.vue";
import GoTravel from "@views/goTravel/GoTravel.vue";
import Scenery from "@/views/goTravel/scenery/Scenery.vue";
import PassLogin from "@/components/passOrCode/PassLogin.vue";
import CodeLogin from "@/components/passOrCode/CodeLogin.vue";
import PersonalIndex from "@/views/personal/Index.vue";
import Search from "@/views/search/Search.vue";
import NotFound from "@/views/error/NotFound.vue";

export const routes: Array<RouteRecordRaw> = [
  {
    path: "/",
    name: "Index", //App中包裹Index
    meta: {
      title: "首页",
      keepAlive: false,
      // requireLogin: true, //先加在这里，表示需要登录！
    },
    component: Index,
    redirect: "/home", //Index中包裹Home等组件
    children: [
      {
        path: "/home",
        name: "Index",
        // component: () => import("@/views/Home.vue"), //这个不行，会加载不出来
        component: Home,
        meta: { title: "首页", keepAlive: false, showTab: true },
      },
      {
        path: "/goTravel",
        name: "GoTravel",
        component: GoTravel,
        meta: { title: "去旅游", keepAlive: false, showTab: true },
        // redirect: "/goTravel/city",
        children: [
          {
            path: "scenery",
            name: "Scenery",
            component: Scenery,
            meta: {
              title: "景区页",
              keepAlive: false,
              showTab: true,
            },
            redirect: "/goTravel/scenery/list",
            children: [
              {
                path: "list",
                name: "SceneryList",
                component: () =>
                  import("@/views/goTravel/scenery/SceneryList.vue"),
                meta: {
                  title: "景区列表",
                  keepAlive: false,
                  showTab: true,
                },
                props({ params: { keyword } }) {
                  return {
                    keyword,
                  };
                },
              },
              {
                path: "detail/:sceneryId",
                name: "SceneryDetail",
                component: () =>
                  import("@/views/goTravel/scenery/SceneryDetail.vue"),
                meta: {
                  title: "景区详情",
                  keepAlive: false,
                  showTab: true,
                },
                props(route) {
                  return {
                    sceneryId: route.params.sceneryId,
                  };
                },
              },
            ],
          },
        ],
      },
      {
        path: "/goTravel/question",
        name: "Question",
        component: () => import("@/views/goTravel/Question.vue"),
        meta: {
          title: "智能问答",
          keepAlive: false,
          showTab: true,
        },
      },
      {
        path: "/personal",
        name: "Personal",
        component: PersonalIndex,
        meta: {
          title: "个人中心",
          keepAlive: false,
          showTab: true,
          requireLogin: true,
        },
        redirect: "/personal/center",
        children: [
          {
            path: "center",
            name: "Center",
            component: () => import("@/views/personal/Center.vue"),
            meta: {
              title: "首页",
              keepAlive: false,
              showTab: true,
              requireLogin: true,
            },
          },
          {
            path: "foot",
            name: "Foot",
            component: () => import("@/views/personal/Foot.vue"),
            meta: {
              title: "足迹",
              keepAlive: false,
              showTab: true,
              requireLogin: true,
            },
          },
          {
            path: "mynote",
            name: "MyNote",
            component: () => import("@/views/personal/MyNote.vue"),
            meta: {
              title: "游记",
              keepAlive: false,
              showTab: true,
              requireLogin: true,
            },
          },
          {
            path: "star",
            name: "Star",
            component: () => import("@/views/personal/Star.vue"),
            meta: {
              title: "我收藏的游记",
              keepAlive: false,
              showTab: true,
              requireLogin: true,
            },
          },
          {
            path: "myroute",
            name: "MyRoute",
            component: () => import("@/views/personal/MyRoute.vue"),
            meta: {
              title: "我的行程",
              keepAlive: false,
              showTab: true,
              requireLogin: true,
            },
          },
          {
            path: "myteam",
            name: "MyTeam",
            component: () => import("@/views/personal/myteam/MyTeam.vue"),
            meta: {
              title: "我的队伍",
              keepAlive: false,
              showTab: true,
              requireLogin: true,
            },
            redirect: "/personal/myteam/myjoin",
            children: [
              {
                path: "myjoin",
                name: "MyJoin",
                component: () => import("@/views/personal/myteam/MyJoin.vue"),
                // component: Note,
                meta: {
                  title: "我加入的队伍",
                  keepAlive: false,
                  showTab: true,
                  requireLogin: true,
                },
              },
              {
                path: "mycreate",
                name: "MyCreate",
                component: () => import("@/views/personal/myteam/MyCreate.vue"),
                // component: Note,
                meta: {
                  title: "我创建的队伍",
                  keepAlive: false,
                  showTab: true,
                  requireLogin: true,
                },
              },
            ],
          },
          {
            path: "follow",
            name: "Follow",
            component: () => import("@/views/personal/Follow.vue"),
            meta: {
              title: "我的粉丝和关注",
              keepAlive: false,
              showTab: true,
              requireLogin: true,
            },
          },
          {
            path: "buy",
            name: "Buy",
            component: () => import("@/views/personal/Buy.vue"),
            meta: {
              title: "我的订单",
              keepAlive: false,
              showTab: true,
              requireLogin: true,
            },
          },
          {
            path: "setup",
            name: "Setup",
            component: () => import("@/views/personal/Setup.vue"),
            meta: {
              title: "设置",
              keepAlive: false,
              showTab: true,
              requireLogin: true,
            },
          },
        ],
      },
      {
        path: "/search",
        name: "Search",
        component: Search,
        meta: { title: "全局搜索结果页", keepAlive: false, showTab: true },
        // beforeEnter: (to, from, next) => {
        //   if()
        //   next();
        // },
        props(route) {
          return {
            keyword: route.params.keyword,
          };
        },
      },
    ],
  },
  {
    path: "/login",
    name: "LoginAndRegister",
    component: LoginAndRegister,
    meta: {
      title: "登录页",
      keepAlive: false,
      showTab: true,
    },
    redirect: "/login/passLogin", //LoginAndRegister中包裹passLogin
    children: [
      {
        path: "passLogin",
        name: "PassLogin",
        // component: () => import("@/components/passOrCode/PassLogin.vue"),
        component: PassLogin,
        meta: { title: "密码登录", keepAlive: false, showTab: true },
      },
      {
        path: "codeLogin",
        name: "CodeLogin",
        // component: () => import("@/components/passOrCode/CodeLogin.vue"),
        component: CodeLogin,
        meta: { title: "验证码登录", keepAlive: false, showTab: true },
      },
    ],
  },
  {
    path: "/404",
    name: "notFound",
    component: NotFound,
  },
  {
    path: "/:pathMatch(.*)*", // 此处需特别注意置于最底部
    redirect: "/404",
  },
];
